<?php
namespace app\common\model;

class Car extends Base
{

    public function getTypeTextAttr($value,$data)
    {
        $status = [1=>'坐骑',2=>'头饰'];
        return $status[$data['type']];
    }

    public function getList($map = []){
        return $this->where($map)
            ->order('sort')
            ->paginate('',false,['query'=>request()->param()]);
    }

    public function getCar($map = [])
    {
        return $this->where($map)->order('sort')->field('img,car_id,thumbnail,price,car_name,day as expire_time')->select();
    }

    public function headWear($map,$this_user = 0)
    {
        $rows = $this->where($map)->order('sort')->field('img,car_id,thumbnail,price,car_name,day as expire_time')->cache(1)->select();

        foreach ($rows as $k => $v){
            $rows[$k]['expire_time'] = $v['expire_time'].'天';
            $map['user_id'] = $this_user;
            $map['type']    = 2;
            $map['car_id']  = $v['car_id'];
            $data = MyCar::where($map)->find();

            if ($data && $data['expire_time'] !== '已过期'){
                $rows[$k]['expire_time'] = $data['expire_time'];
                $rows[$k]['is_buy'] = 1;
            }else{
                $rows[$k]['is_buy'] = 0;
            }

            $rows[$k]['is_use'] = $data['is_use']??0;
        }
        return $rows;

    }
}